from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
from SocketServer import ThreadingMixIn
import threading

class Handler(BaseHTTPRequestHandler):

    def do_GET(self):
        self.send_response(200)
        self.end_headers()
        resp = dispatche(self.path)
        self.wfile.write(resp)
        self.wfile.write('\n')
        return

    def do_POST(self):
        self.send_response(200)
        self.end_headers()
        resp = dispatche(self.path)
        self.wfile.write(resp)
        self.wfile.write('\n')
        return

def dispatche(path):
    if path == "/":
        return "Hello World"
    elif path == "/token":
        return {"ret_code":1, "ret_msg": "success", "expires_in": 2592000,"access_token":"fdsfsdf5445fdsf"}
    elif path == "/getCredit":
        return {"ret_code":1, "ret_msg": "success","application_id": "loan0001","score":678, "pd":0.47543}
    else :
        return "Hello World"

class ThreadedHTTPServer(ThreadingMixIn, HTTPServer):
    """Handle requests in a separate thread."""

if __name__ == '__main__':
    server = ThreadedHTTPServer(('localhost', 8080), Handler)
    print 'Starting server, use <Ctrl-C> to stop'
    server.serve_forever()